import rp from 'request-promise-native';

class Util {
    static postRequest(url, formData) {
        rp.post(url, { form: formData });
    }

    static signRequestData(requestData) {
        let sign;
        let md5sum;

        requestData = JSON.stringify(requestData);
        md5sum = crypto.createHash('md5');
        md5sum.update(requestData);
        md5sum.update(this.options.AppKey);
        sign = md5sum.digest('hex');
        sign = (new Buffer(sign)).toString("base64");

        return {
            DataSign: encodeURIComponent(sign),
            RequestType: this.options.type,
            RequestData: encodeURIComponent(requestData),
            DataType: this.options.DataType,
            EBusinessID: this.options.EBusinessID
        };
    }
}